package mest.controller.hws;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
import mest.entity.warehouse_purchase;
import mest.service.system.DBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import mest.service.hws.warehouse_purchaseService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/warehouse_purchaseController")
@CrossOrigin
public class warehouse_purchaseController {

    @Resource
    private warehouse_purchaseService warehouse_purchaseService;
    @Autowired
    private DBService dbService;

    //测试用，无关要紧
    @RequestMapping("/ab")
    public void ab(@RequestBody JSONArray json) {
        //新增计划采购单
        System.out.println("进入新方法:" + json.toJSONString());
//        Map<String, Object> map = json.toJavaObject(Map.class);
        List<Map> list = json.toJavaObject(List.class);

        System.out.println("前端输入的值" + list.toArray());
        for (Map ab:list){
            System.out.println(ab);
        }

        List<Object> list1 = json.toJavaObject(List.class);

        System.out.println("前端输入的值" + list1.toArray());
        for (Object ab:list){
            System.out.println(ab);
        }

    }

    @RequestMapping("/insert")
    public void insert(@RequestBody JSONArray json) {
        String theirDb = dbService.getCompanyDB();
        System.out.println("进入新方法:" + json.toJSONString());
        List<Map<String,Object>> list= json.toJavaObject(List.class);
        System.out.println("单条数据:" + list.get(0));
        warehouse_purchaseService.insert(theirDb,list);
    }


}
